<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">

			<el-form-item label="常数类别">

				<el-select v-model="form.typeId" placeholder="请选择">
					<el-option v-for="item in types" :key="item.id" :label="item.name" :value="item.id">
					</el-option>
				</el-select>




			</el-form-item>
			<el-form-item label="代码">
				<el-input v-model="form.code"></el-input>
			</el-form-item>
			<el-form-item label="名称">
				<el-input v-model="form.name"></el-input>
			</el-form-item>
			<el-form-item label="显示序号">
				<el-input v-model="form.sort"></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>

<script>
	export default {
		name: 'ConstantItemEdit',
		components: {

		},
		props: [
			'showEdit',
			'id'
		],
		data() {
			return {
				types: [],
				form: {
					id: '',
					typeId: null,
					code: '',
					name: '',
					sort: 0,
					active: null,
				}
			}
		},
		methods: {
			save() {


				this.axios.get('/contant_item?type=save', (data) => {
					if (data) {
						this.$emit('update:showEdit', false)
						this.$emit('update')
					}

				}, this.form, '保存成功');
			},
			queryConstantType() {
				this.axios.get('/constant_type?type=listAll', (data) => {
					this.types = data;
				});
			}
		},
		created() {
				
			this.queryConstantType();

			if (this.id) {
				//当修改的时候 需要根据用户的 id， 将数据查询到页面
				this.axios.get('/contant_item?type=toEdit', (data) => {
					this.form = data;
				}, {
					id: this.id
				});

			}

		}
	}
</script>

<style>
</style>
